package com.model.dao;

import java.beans.Statement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.model.dbutil.DBUtil;

public class UserDao {
	private Connection conn = null;
	PreparedStatement pstmt = null;
	Statement stmt = null;
	ResultSet rs = null;

	public UserDao() {
		conn = DBUtil.getConnection();
	}
	public void loginprocess(com.model.bean.UserBean userBean)
	throws SQLException
	{
		
	}
	public boolean registrationProcess(
			com.model.bean.UserBean RegistrationEntity) {
		return false;
	}

	public boolean registrationprocess(com.model.bean.UserBean RegistrationEntity) throws SQLException {
		boolean flag = false;
		// long id = getLatestPersonId();
		String userQuery = "INSERT INTO userrecords (firstname,lastname,mobile,address,gender,state,city,email,password)VALUES(?,?,?,?,?,?,?,?,?)";
		System.out.println("Query:::::::::::::::>" +userQuery);
		pstmt = conn.prepareStatement(userQuery);

		int count = 0;
		pstmt.setString(1, RegistrationEntity.getFirstname());
		pstmt.setString(2, RegistrationEntity.getLastname());
		pstmt.setString(3, RegistrationEntity.getMobile());
		pstmt.setString(4, RegistrationEntity.getAddress());
		pstmt.setString(5, RegistrationEntity.getGender());
		pstmt.setString(6, RegistrationEntity.getState());
		pstmt.setString(7, RegistrationEntity.getCity());
		pstmt.setString(8, RegistrationEntity.getEmail());
		pstmt.setString(9, RegistrationEntity.getPassword());

		count = pstmt.executeUpdate();
		if (count > 0) {
			flag = true;
			return flag;
		}
		
		boolean productprocess(com.model.bean.UserBean ProductEntity) throws SQLException {
			boolean flag = false;
			// long id = getLatestPersonId();
			String userQuery = "INSERT INTO userrecords (product_name,product_price,product_des,product_qntyavail)VALUES(?,?,?)";
			System.out.println("productQuery:::::::::::::::>" +userQuery);
			pstmt = conn.prepareStatement(userQuery);

			int count = 0;
			pstmt.setString(1, ProductEntity.getProduct_name());
			pstmt.setString(2, ProductEntity.getProduct_price());
			pstmt.setString(3, ProductEntity.getProduct_des());
			pstmt.setString(3, ProductEntity.getproduct_qntyavail());
			

			count = pstmt.executeUpdate();
			if (count > 0)
			{
				flag = true;
				return flag;
			}
		}
			
			boolean catagoryprocess(com.model.bean.UserBean CatagoryEntity) throws SQLException {
				boolean flag = false;
				// long id = getLatestPersonId();
				String userQuery = "INSERT INTO userrecords (cat_name,cat_des)VALUES(?,?)";
				System.out.println("catagoryQuery:::::::::::::::>" +userQuery);
				pstmt = conn.prepareStatement(userQuery);

				int count = 0;
				pstmt.setString(1, CatagoryEntity.getCat_name());
				pstmt.setString(2, CatagoryEntity.getCat_des());
				

				count = pstmt.executeUpdate();
				if (count > 0) {
					flag = true;
					return flag;
				}
			}
			
			boolean orderprocess(com.model.bean.UserBean orderEntity) throws SQLException {
				boolean flag = false;
				// long id = getLatestPersonId();
				String userQuery = "INSERT INTO userrecords (ord_qunt,ord_date,ord_total)VALUES(?)";
				System.out.println("orderQuery:::::::::::::::>" +userQuery);
				pstmt = conn.prepareStatement(userQuery);

				int count = 0;
				pstmt.setString(1, orderEntity.getord_qunt());
				pstmt.setString(1, orderEntity.getord_date());
				pstmt.setString(1, orderEntity.getord_total());
				

				count = pstmt.executeUpdate();
				if (count > 0) {
					flag = true;
					return flag;
				}
			}
		pstmt.close();
		return flag;
	}

}

